import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './plugins/element.js'
import './assets/css/global.css'
import axios from 'axios'
import treeTable from 'vue-table-with-tree-grid'
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme
// 实现请求请求数据时，项目顶部有加载进度条
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'

// 设置请求根路径
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'
// axios.defaults.baseURL = 'https://www.liulongbin.top:8888/api/private/v1/'
// axios.defaults.baseURL = 'http://itcgq.com:8888/'
// 挂载请求拦截器
axios.interceptors.request.use(config => {
  // 数据发生请求时，开启加载进度条
  nprogress.start()
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})
// 响应请求拦截器
axios.interceptors.response.use(config => {
  // 数据请求成功，关闭加载进度条
  nprogress.done()
  return config
})
// 全局过滤器组件
Vue.filter('formatTime', function(data) {
  // 格式换商品创建时间
  function addZero(str) {
    return str.length === 1 ? '0' + str : str
  }

  const d = new Date(data)
  const year = d.getFullYear()
  const month = addZero(d.getMonth() + 1)
  const day = addZero(d.getDay())

  const hh = addZero(d.getHours())
  const mm = addZero(d.getMinutes())
  const ss = addZero(d.getSeconds())
  return `${ year }-${ month }-${ day } ${ hh }:${ mm }:${ ss }`
})
Vue.use(VueQuillEditor)
// 将axios挂载到vue原型上
Vue.prototype.$http = axios
Vue.config.productionTip = false
Vue.component('tree-table', treeTable)

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
